package icu.bughub.app.app

import android.os.Bundle
import android.view.View
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.core.view.WindowCompat
import icu.bughub.app.app.ui.screens.MainFrame
import icu.bughub.app.app.ui.theme.JetpackComposeBasicTheme

/**
 * 项目实战
 *
 * https://www.bilibili.com/video/BV1aS4y1D7dv/?p=2&spm_id_from=pageDriver&vd_source=e07cc8cc94eb22bd76722071b03cd199
 */
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)


        // 设置沉浸式，方式1
        // 让内容，显示在状态栏和系统导航栏后面：状态栏和导航栏会遮盖部分内容
        // 其实是设置xml的 android:fitsSystemWindows 属性
//        WindowCompat.setDecorFitsSystemWindows(window, false)

        // 设置沉浸式，方式2
//        // 采用另外的方式
//        // 设置动态栏颜色，处理不同机型，状态栏不透明问题
//        window.statusBarColor = Color.Transparent.value.toInt()
//        // 让内容，显示在状态栏和系统导航栏后面
//        // 处理不同机型，导航栏遮盖内容问题
//        window.decorView.systemUiVisibility =
//            View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE

        // 设置沉浸式，方式3
        WindowCompat.setDecorFitsSystemWindows(window, false)


        // 获取状态栏高度
        var statusBarHeight = 0
        val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")

        if (resourceId > 0) {
            statusBarHeight = resources.getDimensionPixelOffset(resourceId)
        }


        setContent {
            JetpackComposeBasicTheme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    MainFrame(statusBarHeight = statusBarHeight)
                }
            }
        }
    }

    @Preview
    @Composable
    fun MainFramePreview() {
        JetpackComposeBasicTheme {
            // A surface container using the 'background' color from the theme
            Surface(
                modifier = Modifier.fillMaxSize(),
                color = MaterialTheme.colorScheme.background
            ) {
                MainFrame(statusBarHeight = 30)
            }
        }
    }
}
